using System.Collections.Generic;
using UnityEngine;
using Voodoo.Utils;

namespace Voodoo.Pattern.Random
{
	public static class RandomizeFlag
	{
		public static Sprite GetRandomFlagSprite(FlagPool _list)
		{
			if (_list == null || _list.flags.Count == 0)
			{
				return null;
			}
			return _list.flags.GetRandomValue();
		}

		public static List<Sprite> GetRandomFlagSprites(FlagPool _list, int _numberRequired, bool _duplicateAllowed = false)
		{
			List<Sprite> list = new List<Sprite>();
			if ((_list?.flags?.Count).GetValueOrDefault() <= 0 || _numberRequired == 0)
			{
				return list;
			}
			List<Sprite> list2 = new List<Sprite>(_list.flags);
			for (int i = 0; i < _numberRequired; i++)
			{
				int index = UnityEngine.Random.Range(0, list2.Count);
				list.Add(list2[index]);
				if (!_duplicateAllowed)
				{
					list2.RemoveAt(index);
					if (list2.Count == 0)
					{
						Debug.Log("Not enough element in " + _list.name + " to have no duplicate");
						list2.AddRange(_list.flags);
					}
				}
			}
			return list;
		}
	}
}
